<template>
  <!-- 个人信息查看 -->
  <div class="personal-container">
    <el-card class="box-card">
      <div class="title">个人信息查看</div>
      <div class="body">
        <field
          :classes="this.class"
          :department="this.department"
          :dormitoryNum="this.dormitoryNum"
          :sex="this.sex"
          :studentName="this.studentName"
          :studentNum="this.studentNum"
          :studentPhone="this.phone"
          :balance="this.balance"
        ></field>
        <div class="card-info">
          <span>一卡通状态</span>
          <el-tag v-if="!this.cardStatus && !this.tag" type="info">未申请</el-tag>
          <el-tag v-if="!this.cardStatus && this.tag == 1" type="primary">待审核</el-tag>
          <el-tag v-if="this.cardStatus == 1 && !this.tag" type="success">正常</el-tag>
          <el-tag v-if="this.cardStatus == 2 && !this.tag" type="danger">已挂失</el-tag>
        </div>
      </div>
    </el-card>
  </div>
</template>

<script>
import field from '../../components/field.vue'
import commonServe from '../../api/service/common.serve'
export default {
  components: {
    field
  },
  data() {
    return {
      id: window.sessionStorage.getItem('studentId'),
      studentNum: '',
      studentName: '',
      department: '',
      class: '',
      dormitoryNum: '',
      sex: '',
      phone: '',
      cardStatus: '',
      tag: '',
      balance: ''
    }
  },
  created() {
    this.getUserInfo(), this.getCardStatus()
  },
  methods: {
    getUserInfo() {
      commonServe
        .getStudentInfo(this.id)
        .then((res) => {
          console.log(res)
          if (res.code === 200) {
            let obj = res.data.item
            this.studentNum = obj.studentNum
            this.studentName = obj.studentName
            this.department = obj.department
            this.class = obj.classes
            this.dormitoryNum = obj.dormitoryNum
            this.sex = obj.sex
            this.phone = obj.studentPhone
          } else {
            this.$message.warning('获取学生信息失败，请刷新重试')
          }
        })
        .catch((err) => {
          this.$message.warning('获取学生信息失败，请刷新重试' || err.message)
        })
    },
    // 获取一卡通状态
    getCardStatus() {
      commonServe.getCardInfo(this.id).then((res) => {
        console.log(res)
        if (res.code === 200) {
          this.cardStatus = res.data.card.cardStatus
          this.tag = res.data.card.tag
          this.balance = res.data.card.balance
        }
      })
    }
  }
}
</script>

<style lang="less" scoped>
.personal-container {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  .box-card {
    width: 80%;
    .title {
      font-size: 30px;
      color: #3a62d7;
      letter-spacing: 10px;
      font-weight: bold;
      text-shadow: 2px 2px 5px #999;
    }
    .body {
      padding: 60px 50px 0 50px;
      .card-info {
        padding: 10px;
        display: flex;
        align-items: center;
        span {
          width: 80px;
          font-size: 14px;
        }
        .el-tag {
          text-align: center;
        }
      }
      .card-info {
        padding: 10px;
        display: flex;
        align-items: center;
        span {
          width: 80px;
          font-size: 14px;
        }
      }
    }
  }
}
</style>
